#!/usr/bin/env python
# coding: utf-8

# In[2]:


import pandas as pd
import requests,json
hw_key = "074c0cf252bce9288b8a774fb78814e7"


# In[44]:


def geocode(key,address,city=None,batch='false',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
    'key':hw_key,
    'address':address,
    'city':city,
    'batch':batch,
    'sig':sig,
    'output':output,
    'callback':callback
    }
    response=requests.get(url,params=params)
    results=response.json()['geocodes'][0]['location']
    # return
    return results


# In[3]:


def regeo(key,location,poitype=None,radius="1000",extensions='base',batch='false',roadlevel=None,sig=None,
          output='json',callback=None,homeorcorp='0'):
    # 通过经纬度来判断位置
    url='https://restapi.amap.com/v3/geocode/regeo?parameters'
    params={
        'key':key,
        'location':location,
        'poitype':poitype,
        'radius':radius,
        'extensions':extensions,
        'batch':batch,
        'sig':sig,
        'output':output,
        'callback':callback,
        'homeorcorp':homeorcorp
    }
    response=requests.get(url,params)
    results=response.json()
    return results


# In[50]:


def walking(key,origin,location,sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':location,
        'sig':sig,
        'output':output,
        'callback':callback,     
    }
    response=requests.get(url,params=params)
    results=response.json()
    return results


# In[59]:


def bus(key,origin,destination,city,cityd=None,extensions="base",strategy=0,nightflag=0,date=None,time=None,sig=None,output="json",callback=None):
    bus_url = "https://restapi.amap.com/v3/direction/transit/integrated?parameters"
    params ={
        "key":key,
        "origin":origin,
        "destination":destination,
        "city":city
    }
    r = requests.get(bus_url,params=params)
    result = r.json()
    return result


# In[6]:


def driving(key,origin,destination,extensions):
    driving_url='https://restapi.amap.com/v3/direction/driving?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'extensions':extensions   
    }
    r = requests.get(driving_url,params=params)
    result = r.json()
    return result


# In[11]:


def bicycling(key,origin,destination):
    bicycling_url='https://restapi.amap.com/v4/direction/bicycling?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination, 
    }
    r = requests.get(bicycling_url,params=params)
    result = r.json()
    return result


# In[13]:


def truck(key,origin,destination,size):
    truck_url='https://restapi.amap.com/v4/direction/truck?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination, 
        'size':size
    }
    r = requests.get(truck_url,params=params)
    result = r.json()
    return result


# In[78]:


def district(key,keywords=None,subdistrict=1,page=1,offset=20,extensions="base",filter="",callback=None,output="json"):
    district_url = "https://restapi.amap.com/v3/config/district?parameters"
    params ={
        "key":key,
        "keywords":keywords,
        "subdistrict":subdistrict,
        "page":page,
        "offset":offset,
        "extensions":extensions,
        "filter":filter,
        "callback":callback,
        "output":output
    }
    r = requests.get(district_url,params=params)
    result = r.json()
    return result


# In[94]:


def POI(key,keywords,types,city,citylimit="false",children=0,offset=20,page=1,extensions="base",sig=None,output="json",callback=None):
    POI_url = "https://restapi.amap.com/v3/place/text?parameters"
    params ={
        "key":key,
        "keywords":keywords,
        "types":types,
        "page":page,
        "city":city,
        "extensions":extensions,
        "citylimit":citylimit,
        "children":children,
        "page":page,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback
    }
    r = requests.get(POI_url,params=params)
    result = r.json()
    return result


# In[115]:


def around(key,keywords,location,city,types,radius=3000,sortrule="distance",offset=20,page=1,extensions="base",sig=None,output="json",callback=None):
    around_url = "https://restapi.amap.com/v3/place/around?parameters "
    params ={
        "key":key,
        "keywords":keywords,
        "types":types,
        "page":page,
        "city":city,
        "extensions":extensions,
        "location":location,
        "extensions":extensions,
        "sig":sig,
        "output":output,
        "callback":callback,
        "radius":radius,
        "sortrule":sortrule
    }
    r = requests.get(around_url,params=params)
    result = r.json()
    return result


# In[32]:


def ip(key,id):
    url='https://restapi.amap.com/v3/ip?parameters'
    key="074c0cf252bce9288b8a774fb78814e7"
    params={
        'key':key,
        'ip':id
      
    }
    response=requests.get(url,params)
    results=response.json()
    return results


# In[119]:


def amap(key,location,zoom,size='400*400',scale='1',markers=None,labels=None,paths=None,traffic='0',sig=None):
    amap_url='https://restapi.amap.com/v3/staticmap?parameters'
    params={
    'key':key,
    'location':location,
    'zoom':zoom,
    'scale':scale,
    'markers':markers,
    'labels':labels,
    'paths':paths,
    'traffic':traffic,
    'sig':sig
    }
    r=requests.get(amap_url,params)
    data=r.url
    return data


# In[135]:


def convert(key,locations,coordays='',sig='',output=''):
    convert_url='https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'
    params={
        'key':key,
        "locations":locations,
        'coordays':coordays,
        'sig':sig,
        'output':output
    }
    r = requests.get(convert_url,params=params)
    result = r.json()
    return result


# In[137]:


def weather(key,city,extensions='base',output=''):
    weather_url='https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    params={
        'key':key,
       'city':city,
        'extensions':extensions,
        'output':output
    }
    r = requests.get(weather_url,params=params)
    result = r.json()
    return result


# In[148]:


def input(key,keywords,type=None,location=None,city=None,
          citylimit='false',datatype=None,sig=None,output='json',callback=None):
    input_url='https://restapi.amap.com/v3/assistant/inputtips?parameters'
    params={
        'key':key,
        'keywords':keywords,
        'type':type,
        'location':location,
        'city':city,
        'citylimit':citylimit,
        'datatype':datatype,
        'sig':sig,
        'output':output,
        'callback':callback
    }
    r = requests.get(input_url,params=params)
    result = r.json()
    return result


# In[40]:


def rectangle(key,rectangle,level='5',extensions='base',sig=None,output='json',callback=None):
    url='https://restapi.amap.com/v3/traffic/status/rectangle?parameters'
    params={
        'key':key,
        'rectangle':rectangle,
        'level':level,
        'extensions':extensions,
        'sig':sig,
        'output':output,
        'callback':callback,
    }
    response=requests.get(url,params)
    r=response.json()
    return r

